<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Trang chủ - Quản lý</title>
<link rel="shortcut icon" href="../Images/Icons/SunstormLogo.gif" />
<link href="../Twitter_Bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../CSS/css_admin.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../CSS/validationEngine.jquery.css"/>

<script type="text/javascript" src="../Twitter_Bootstrap/js/jquery.js"></script>
<script type="text/javascript" src="../Twitter_Bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="../Scripts/jquery.gvChart-1.1.js"></script>
<script type="text/javascript">
	gvChartInit();
	jQuery(document).ready(function(){
			jQuery('#myTable').gvChart({
				chartType: 'PieChart',
				gvSettings: {
					vAxis: {title: 'Chuyên mục'},
					hAxis: {title: 'Lượt xem'},
					width: 720,
					height: 300
					}
			});
									}); 
</script>

</head>

<body>
<div class="container" id="Container">
<!--Menu top -->
  <div id="menu">
  	<?php session_start();
		include("MainMenu.php");
		include("../Connections/connect_admin.php");
		$urlNews="../Images/Img_News/";
		
	?>
    
    </div>
  </div>
  <div id="divContain">
  <!--Support Info -->
  <div id="quickview" >

    <div id="userinfo" class="box thumbnail">
    	<table width="100%" border="0" cellspacing="0" cellpadding="10">
          <tr>
            <td><img src="../Images/Img_User/<?php echo $_SESSION["avatar"]; ?>" width="100px" height="120px"/></td>
            <td style="line-height:18px">
            	Xin chào,<br /><b><?php echo $_SESSION["username"]; ?></b><br />
            	<a href="MyProfile.php">Hồ sơ cá nhân</a><br />
                <a href="#changepass" data-toggle="modal" onclick="Reset();">Đổi mật khẩu</a><br />
                <a href="Login.php">Thoát</a>
            </td>
          </tr>
    	</table>

    </div>
 
    <div id="tophotnews" class="box thumbnail">
    	<h3>bài đọc nhiều</h3>
      
         <ul class="hotnews">
        	<?php 
			$query="SELECT n.NewsID, n.Title, n.Image, n.Views,n.CreatedDate FROM news n WHERE n.IsDeleted=0 ORDER BY n.Views DESC LIMIT 0,5";
			$res1=mysql_query($query);
			while($hot=mysql_fetch_assoc($res1))
			{
			?>
            	<li> 
                	<img src="<?php echo $urlNews.$hot["Image"]; ?>" alt="" style="width:80px; height:50px; position:absolute" />
                    <div style="margin-left:90px">
                    	<a href="WriteNews.php?id=<?php echo $hot["NewsID"]; ?>"><?php echo $hot["Title"]; ?></a>
                        <div>Số lượt xem: <?php echo $hot["Views"];?></div>
                    </div>
                </li>
            <?php
			}
			?>
          </ul>
        
    </div>
  
    <div id="topmarknews" class="box thumbnail">
    	<h3>Bài đánh giá cao</h3>
       
        <ul>
        	<?php 
			$query="SELECT n.NewsID, n.Title, n.Image,n.Rating,n.MarkerNum,n.CreatedDate FROM news n WHERE n.IsDeleted=0 ORDER BY n.Rating DESC, n.MarkerNum DESC  LIMIT 0,5";
			$res2=mysql_query($query);
			while($news=mysql_fetch_assoc($res2))
			{
			?>
            	<li> 
                	<img src="<?php echo $urlNews.$news["Image"]; ?>" alt="" style="width:80px; height:50px; position:absolute" />
                    <div style="margin-left:90px">
                    <a href="WriteNews.php?id=<?php echo $news["NewsID"]; ?>"><?php echo $news["Title"]; ?></a>
                     <div>Đánh giá: <?php echo $news["Rating"];?></div>
                     <div>Số lượt đánh giá: <?php echo $news["MarkerNum"];?></div>
                     </div>
                </li>
            <?php
			}
			?>
          </ul>
      
    </div>
    
  </div>
  <!--Content -->
  <div id="content">
  	<h3 id="area">Thống kê số lượt xem</h3>
		
			<table id='myTable'>
				
				<thead>
					<tr>
						<th></th>
                      <?php
					  $query="SELECT t.TopicName,t.TopicID FROM topic t WHERE t.IsDeleted=0 AND t.ParentID=0 AND t.IsAllowWriteNews=1 ORDER BY t.OrderIndex";
					  $result=mysql_query($query);
					  while($tp=mysql_fetch_assoc($result))
					  {
					  ?>
						<th><?php echo $tp["TopicName"]; ?></th>
					<?php 
					}
					?>
					</tr>
				</thead>
					<tbody>
					<tr>
						<th>Lượt xem</th>
                 <?php
				 function getSubMenu($parent)
					{
						$submenu='';
						$res1=mysql_query("SELECT t.TopicID FROM topic t WHERE t.IsDeleted=0 and t.ParentID=$parent");
						while($t=mysql_fetch_assoc($res1))
						{
							$submenu.='<'.$t["TopicID"].'>';
							$submenu.=getSubMenu(intval($t["TopicID"]));
						}
						return $submenu;
					}
					//-----------------------------------------------------------------
					  $query="SELECT t.TopicName,t.TopicID FROM topic t WHERE t.IsDeleted=0 AND t.ParentID=0 AND t.IsAllowWriteNews=1 ORDER BY t.OrderIndex";
					  $result=mysql_query($query);
					 while($t=mysql_fetch_assoc($result))
					{
					$listTopic='<'.$t["TopicID"].'>'.getSubMenu(intval($t["TopicID"]));
					$topsql="SELECT sum(n.Views) as Sum FROM news n WHERE n.IsDeleted=0 AND '$listTopic' LIKE CONCAT('%<',n.TopicID,'>%')";
					
					$sum=mysql_query($topsql);
					$kq=mysql_fetch_assoc($sum);
?>
				
						<td><?php echo $kq["Sum"]; ?></td>
						<?php
						}?>
					</tr>
					
				</tbody>
			</table>
  </div>
  
  </div>
  <!--footer -->
  <div id="footer">
<?php
	 	include("Footer.php");
	 ?>
  </div>
</div>

</body>

</html>
